﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace saveText
{
    public partial class Form1 : Form
    {
        private int[] tmp = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string sysYear = DateTime.Now.Year.ToString();
            string sysMouth = DateTime.Now.Month.ToString();
            string sysDay = DateTime.Now.Day.ToString();
            string sysHour = DateTime.Now.Hour.ToString();
            string sysMinute = DateTime.Now.Minute.ToString();
            string sysSecond = DateTime.Now.Second.ToString();

            string folderName = sysYear + sysMouth + sysDay;
            string fileName = sysHour + sysMinute + sysSecond;

            if (!Directory.Exists(@"C:\" + folderName))
            {
                // Create the directory it does not exist.
                Directory.CreateDirectory(@"C:\" + folderName);
            }

            StreamWriter mStreamWriter = new System.IO.StreamWriter(textBox1.Text + folderName + @"\" + fileName + "_data.txt", false, System.Text.Encoding.UTF8);
            for (int i = 0; i < tmp.Length; i++)
            {
                mStreamWriter.WriteLine(tmp[i]);
            }
            mStreamWriter.Close();
            mStreamWriter.Dispose();
            mStreamWriter = null;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            List<int> list = new List<int>();
            using (TextReader reader = File.OpenText(@"C:\001.txt"))
            {
                string s = reader.ReadLine();
                while (s != null)
                {
                    list.Add(ToIntArray(s));
                    s = reader.ReadLine();
                }
            }

            //转换结果
            int[] result = list.ToArray();
        }

        private static int ToIntArray(string s)
        {
            string[] sdata = s.Split(',');
            int data = 0;
            for (int i = 0; i < sdata.Length; i++)
            {
                if (!string.IsNullOrEmpty(sdata[i]))
                {
                    data = int.Parse(sdata[i]);
                }
            }
            return data;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = folderBrowserDialog1.SelectedPath;
            }
        }


    }
}
